##Einlesen der Daten, L??cken mit NA f??llen (fill = T),
##nach Komma getrennt einlesen (sep = ",")
data <- read.table("C:/Users/Melanie/Desktop/RKurs/Precipitation/dataset_precipitation.dat", 
                   fill = T, sep = ",", header = T)

## load necessary packages
library(latticeExtra)

## Variablen definieren
x <- data$dateEAT 
y <- data$precip_wxt
plotID <- data$plotID
type = "l"
xlim = "01.04.2011"
col = "blue"
layout = c(2,1)
main = "Amount of precipitation"
xlab = "Date"
ylab = "Precipitation [mm]"
type_both = "b"
layout = c(1,2)
bg = "grey40"
col_update = "white"
font = 2
## zuweisen der Werte mittels as.POSIXct
x <- as.POSIXct(x)


## define plot object - plain line plot
xy <- xyplot(y ~ x, type = type)

xy

## define plot object - lines per plotID
xy <- xyplot(y ~ x | plotID, 
             type = type, xlim= xlim)


## define plot object - get rid of useless plotID "", change line colour 
## and adjust layout so that panels are plotted columnwise
xy <- xyplot(y ~ x | plotID,
             subset = plotID != "", col = col,
             type = type, layout = layout, main = main, 
             xlab = xlab, ylab = ylab)
xy ## nur linien werden geplottet

## define plot object - plot type using both points and lines
xypoints <- xyplot(y ~ x | plotID,
             subset = plotID != "", col = col,
             type = type_both, layout = layout)
xypoints ## linien und punkte werden geplottet



## define plot object - combine xy and xypoints to one object
combo <- c(xy, xypoints, layout = layout) ## schreibt beide plots 
##(linien und punkte nebeneinander ohne neue Achsen definieren zu m??ssen

combo

## update plot object - adjust strip colour and font --> ??ndert bei allen 
##plotts Farbe o.??.
update(combo, strip = strip.custom(bg = bg, 
                                   par.strip.text = list(col = col_update, 
                                                         font = font)))

## Histogramm
breaks = 20 ## Unterteilungen
freq = TRUE ## TRUE = Absolut; FALSE= prozentuale Anteil ???
density = NULL ## Schraffur --> beliebig Werte einsetzbar
angle = 45 ## Winkel der Schraffur
col = "blue" ## Farbe der Balken
border = NULL ## Farbe der Umrandung der Balken
main = "Histogram of precipitation" ## Histogramm??berschrift
yname <- "number of registrations / 5min" ## yAchsenname
xname <- "precipitation" ## xAchsenname
xlim = c(0,250) ## xAchsenbereich
ylim = c(0,3000) ## yAchsenbereich
plot = TRUE ## Histogramm wird geplottet
labels = FALSE ## TRUE=> exakten Werte werden an die Balken geschrieben, 
##FALSE => wird weggelassen

hist(y, breaks = breaks, freq = freq, 
     include.lowest = TRUE, density = density, angle = angle, col = col,
     border = border, main = main, xlim = xlim,
     ylim = ylim, xlab = xname, ylab = yname, plot = plot, 
     labels = labels)
